package com.boxin.ims.modules.wechat.utils;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Service;

import com.boxin.framework.base.utils.DateUtils;
import com.boxin.ims.modules.momarketing.entity.CouponConfig;
import com.boxin.ims.modules.momarketing.service.CouponConfigService;
import com.boxin.ims.modules.recharge.entity.Recharge;
import com.boxin.ims.modules.recharge.service.RechargeLogService;
import com.boxin.ims.modules.recharge.service.RechargeService;
import com.boxin.ims.modules.wechat.entity.MemberScore;
import com.boxin.ims.modules.wechat.entity.SignupConfig;
import com.boxin.ims.modules.wechat.entity.UserDefine;
import com.boxin.ims.modules.wechat.entity.WechatMember;
import com.boxin.ims.modules.wechat.score.entity.ExchangeRecord;
import com.boxin.ims.modules.wechat.score.entity.ScoreExchange;
import com.boxin.ims.modules.wechat.score.service.ExchangeRecordService;
import com.boxin.ims.modules.wechat.service.MemberScoreService;
import com.boxin.ims.modules.wechat.service.SignupConfigService;
import com.boxin.ims.modules.wechat.service.WechatMemberService;
import com.thinkgem.jeesite.modules.sys.entity.User;

@Service
public class RechargeUtils   implements ApplicationContextAware {
	
	public static Integer DEFAULT_ADD_SCORE = 1;
	
	private static MemberScoreService memberScoreService;
	
	private static WechatMemberService wechatMemberService;
	
	private static CouponConfigService couponConfigService;
	
	private static ExchangeRecordService exchangeRecordService;
	
	private static RechargeService rechargeService;
	
	private static RechargeLogService rechargeLogService;
	
	
	
	
	/**
	 * @author Jakemanse
	 * @time 2014-4-1  上午9:14:41
	 * @function <p> 金额  </p>
	 * @param wechatMember
	 * @param money
	 * @param reason
	 */
	public static void addMoney(WechatMember wechatMember,int money,String reason ){
		
		int leftMoney = wechatMember.getMoney() + money;
		wechatMember.setScore((leftMoney<0)?0:leftMoney);
		wechatMemberService.save(wechatMember);
		
		//查找会员卡
		Recharge recharge = rechargeService.getRechargeByMemberId(wechatMember.getId());
		if(recharge == null){
			recharge = new Recharge();
			recharge.setMember(wechatMember);
			recharge.setMoney(money);
			recharge.setName(wechatMember.getName());
			recharge.setType(Recharge.CARD_TYPE_GENERAL);
			recharge.setUser(wechatMember.getUser());
		}else{
			//int money = recharge.getMoney();
			
		}
		
		
		//生成二维码
		
		
	}
	
	
	 

	@Override
	public void setApplicationContext(ApplicationContext applicationContext)
			throws BeansException {
		
		wechatMemberService = (WechatMemberService)applicationContext.getBean("wechatMemberService");
		rechargeService = (RechargeService)applicationContext.getBean("rechargeService");
		rechargeLogService = (RechargeLogService)applicationContext.getBean("rechargeLogService");
		
	}
	
	

}
